﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SKB.ViewModels;

namespace SKB.Extensions
{
    public static class DistributionExtensions
    {
        static SKB.SKBEntities e = new SKB.SKBEntities();

        public static Project ToProject(this ProjectViewModel o)
        {
            if (o != null)
            {
                return new Project()
                {
                    ProjectID = o.ProjectID,
                    ProjectName = o.ProjectName,
                    ProjectDescription = o.ProjectDescription

                };
            }
            else
            {
                return new Project();
            }
        }

        public static ProjectViewModel ToProjectViewModel(this Project o)
        {
            if (o != null)
            {
                return new ProjectViewModel()
                {
                    ProjectID = o.ProjectID,
                    ProjectName = o.ProjectName,
                    ProjectDescription = o.ProjectDescription

                };
            }
            else
            {
                return new ProjectViewModel();
            }
        }


        public static IEnumerable<ProjectViewModel> ToProjectViewModel(this IEnumerable<Project> list)
        {
            foreach (Project o in list)
            {
                yield return o.ToProjectViewModel();
            }
        }


        // http://stackoverflow.com/questions/12528756/master-details-style-view-in-mvc-4

    }
}